package yangyongchao.com.howtousefastjson;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by yyc on 2018/2/2.
 */

public class MyAdapter extends BaseAdapter {
    private ArrayList<DataBean> mBeanArrayList = new ArrayList<>();
    private LayoutInflater mLayoutInflater;
    private Context mContext;

    public MyAdapter(ArrayList<DataBean> mBeanList, Context context) {
        mBeanArrayList = mBeanList;
        mContext = context;
        mLayoutInflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return mBeanArrayList.size();
    }

    @Override
    public Object getItem(int position) {
        return mBeanArrayList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
//            如果布局不存在则加载布局
            convertView = mLayoutInflater.inflate(R.layout.list_item, parent, false);
            holder = new ViewHolder();
            holder.mTime = (TextView) convertView.findViewById(R.id.time);
            holder.mFtime = (TextView) convertView.findViewById(R.id.ftime);
            holder.mLocation = (TextView) convertView.findViewById(R.id.location);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        DataBean mBean = mBeanArrayList.get(position);
        holder.mTime.setText("送达时间:" +mBean.getTime());
        holder.mFtime.setText("离开时间:" +mBean.getFtime());
        holder.mLocation.setText("地址信息:" +mBean.getLocation());

        return convertView;
    }

    private static class ViewHolder {
        TextView mTime;//运单号
        TextView mFtime;//状态
        TextView mLocation;//寄件地址
    }
}
